// 找出数组中满足和大于等于target的长度最小的连续子数组，并返回其长度，如果不存在符合条件的子数组，返回0

// 思路，滑动窗口
// left和right分别指向窗口的左右边界，保证窗口中的和大于target
function minSubArrayLen(target, nums) {
    let left = 0
    let right = 0
    let window_sum = 0
    let ans = Infinity
    while (right < nums.length) {
        window_sum += nums[right]
        while (window_sum >= target) {
            ans = Math.min(ans, right - left + 1)
            window_sum -= nums[left]
            left++
        }
        right++
    }
    return ans === Infinity ? 0 : ans
}

let nums = [2, 3, 1, 2, 4, 3]
let target = 7
console.log(minSubArrayLen(target, nums));